﻿using Daily.Application.DTO;
using DailyApp.WPF.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace DailyApp.WPF.ViewModels
{
    public class MainWindowViewModel:BindableBase
    {
        private readonly IRegionManager regionManager;
        /// <summary>
        /// 导航记录
        /// </summary>
        private IRegionNavigationJournal journal;
        public MainWindowViewModel(IRegionManager regionManager)
        {
            MenuList =
            [
                new LeftMenuInfo() { Icon = "Home", MenuName ="首页", ViewName = "HomeUC"},
                new LeftMenuInfo() { Icon = "NotebookOutline", MenuName = "代办事项", ViewName = "WaitUC" },
                new LeftMenuInfo() { Icon = "NotebookPlus", MenuName = "备忘录", ViewName = "MemoUC" },
                new LeftMenuInfo() { Icon = "Cog", MenuName = "设置", ViewName = "SettingsUC" },
            ];
            NavigateCommand = new DelegateCommand<LeftMenuInfo>(Navigate);
            GoBackCommand = new DelegateCommand(GoBack);
            GoForwardCommand = new DelegateCommand(GoForward);

            this.regionManager = regionManager;

        }
        #region 实现方法
        public void Init(string UserName) {
            NavigationParameters pairs = new NavigationParameters();
            pairs.Add("UserName", UserName);
            regionManager.Regions["MainViewRegion"].RequestNavigate("HomeUC", p => {
                journal = p.Context.NavigationService.Journal;
            }, pairs);
        }
        private void Navigate(LeftMenuInfo menu)
        {
            if (menu == null || string.IsNullOrEmpty(menu.ViewName)) return;
            regionManager.Regions["MainViewRegion"].RequestNavigate(menu.ViewName,p=> {
                journal = p.Context.NavigationService.Journal;
            });

         }
        private void GoBack()
        {
            if(journal!=null&&journal.CanGoBack)journal.GoBack();
        }
        private void GoForward()
        {
            if(journal!=null&&journal.CanGoForward)journal.GoForward();
        }
        #endregion

        #region 定义方法
        public DelegateCommand<LeftMenuInfo> NavigateCommand { get; set; }
        public DelegateCommand GoBackCommand { get; set; }
        public DelegateCommand GoForwardCommand { get; set; }
        #endregion

        #region 属性
      
        private List<LeftMenuInfo> leftMenuList;

        public List<LeftMenuInfo> MenuList
        {
            get { return leftMenuList; }
            set { leftMenuList = value; RaisePropertyChanged(); }
        }
        #endregion


    }
}
